package edu.ucsd.cse135.gas.action.applicant;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import edu.ucsd.cse135.gas.logic.applicant.Applicant;
import edu.ucsd.cse135.gas.resources.Constants;

public class GetPreviousData extends Action {

	public GetPreviousData() {
		super();
	}
	
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		
		Applicant a = (Applicant)request.getSession().getAttribute("applicant");
		
		if(request.getAttribute("firstName") != null)
		{
			a.setFirstName(request.getAttribute("firstName").toString());
		}
		
		if(request.getAttribute("middleInitial") != null)
		{
			a.setMiddleInitial(request.getAttribute("middleInitial").toString());
		}

		if(request.getAttribute("name") != null)
		{
			a.setName(request.getAttribute("name").toString());
		}
		
		if(request.getAttribute("countryOfCitizenship") != null)
		{
			a.setCountryOfCitizenship(request.getAttribute("countryOfCitizenship").toString());
		}
		
		if(request.getAttribute("countryOfResidence") != null)
		{
			a.setCountryOfResidence(request.getAttribute("countryOfResidence").toString());
		}
		
		if(request.getAttribute("usResidence") != null || a.getCountryOfCitizenship().equals("United States"))
		{
			if(request.getAttribute("usResidence").toString().equals("true"))
			{
				a.setUsResidence(true);
			}
			else if(request.getAttribute("usResidence").toString().equals("false"))
			{
				a.setUsResidence(false);
			}
		}
			return mapping.findForward(Constants.FAILURE);
		
	}
}
